package ext.acae2.dms.web.output;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import wt.log4j.LogR;
import wt.pom.Transaction;

public class DownloadProcessor {

	private static final Logger LOGGER = LogR.getLogger(DownloadProcessor.class
			.getName());

	@SuppressWarnings("rawtypes")
	public File process(Map<String, List> map, String fileName) {

		LOGGER.debug("> Start process");

		Transaction trans = new Transaction();
		File zipFile =null;
		
		try {

			trans.start();

			// 1. Get downloadPath from server.
			LOGGER.debug("---------- Step 1 start ----------");
			String downloadPath = new DownloadFileProcessor().getDownloadPath();
			LOGGER.debug("---------- Step 1 end ----------");

			// 2. To XML.
			LOGGER.debug("---------- Step 2 start ----------");
			boolean b = new ToxmlProcessor().toxml(map, downloadPath, fileName);
			LOGGER.debug("---------- Step 2 end ----------");

			// 3. server file tozip.
			
			LOGGER.debug("---------- Step 3 start ----------");
			if (b == true) {
				zipFile = new TozipProcessor().tozip(downloadPath,
						fileName);
//				String path = zipFile.getAbsolutePath();
				trans.commit();
			}
			LOGGER.debug("---------- Step 3 end ----------");

		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

		LOGGER.debug("> End process");
		return zipFile;
	}
}
